<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('调整承办部门')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <input type="hidden" id="getDealPK" name="getDealPK" th:value="${getDealPK}">
            <input type="hidden" id="pkId" name="pkId" th:value="${wfId}">
            <form id="post-form">

                <div class="select-list">
                    <ul>
                        <li>
                            承办单位：<input type="text" name="sbdeptName"/>
                        </li>
                        <li>
                            办理性质：<input type="text" name="sortName"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>

            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success"  th:onclick="resend()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="mTelRcd:remove:view">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-danger multiple disabled" onclick="backAll()"
               shiro:hasPermission="mTelRcd:remove:view">
                <i class="fa fa-remove"></i> 撤回
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/common/js/common.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "gaoxin/system/mTelWF";
    var twfurgent = ctx + "gaoxin/system/twfurgent";
    var send = ctx + "gaoxin/system/sendBack";

    var wfId = [[${wfId}]];
    $(function () {
        var options = {
            url: prefix + "/cmnFile/sendBackListJson?wfId=" + wfId,
            sortName: "pkId",
            sortOrder: "desc",
            uniqueId: "pkId",
            createUrl: prefix+"/cmnFile/add/{id}",
           // updateUrl: "/system/mTelRcd/telbackaudit/{id}",
            updateUrl: prefix+"/cmnFile/edit/{id}",
            removeUrl: prefix + "/cmnFile/remove",
            saveUrl: twfurgent + "/twfurgentAdd/{id}",
            modalName: "调整承办部门",
            fixedColumns: true,
            fixedNumber: 1,
            fixedRightNumber: 1,
            columns: [{
                checkbox: true
            },
                {field: 'pkId', title: 'pkId', hidden: true, visible: false},
                {field: 'wfId', title: 'wfId', hidden: true, visible: false},
                {field: 'seqName', title: '交办次序', align: 'center', sortable: true},
                {field: 'sortName', title: '办理性质', align: 'center', sortable: true},
                {field: 'dealName', title: '办理方式', align: 'left', halign: 'center', sortable: true},
                {field: 'sbdeptName', title: '承办单位', align: 'center', sortable: true},
                {
                    field: 'sendDesc', title: '办理要求', hidden: true, formatter: function (value, row, index) {
                        if (value != null && value.length > 10) {
                            value = value.substring(0, 6) + "...";
                        }
                        return value;
                    }
                },
                {field: 'sdeptName', title: '派发单位', hidden: true},
                {field: 'backLimit', title: '要求期限', align: 'center', sortable: true, width: 80},
                {field: 'suserName', title: '派发人', hidden: true},
                {field: 'sendTime', title: '派发时间', align: 'center', sortable: true, width: 80},
                {
                    field: 'sendState',
                    title: '办理情况',
                    align: 'center',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return fmtSBSendState(value, row, index);
                    }
                },
                {field: 'getTime', title: '签收时间', align: 'left', halign: 'center', width: 80},
                {field: 'getPerson', title: '签收联系人', align: 'center', sortable: true},
                {field: 'buserName', title: '回复人', align: 'left', halign: 'center'},
                {field: 'backTime', title: '回复时间', align: 'center', sortable: true, width: 80},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editDialog(\'' + row.pkId + '\')"><i class="fa fa-edit"></i>处理</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="EditViewById(\''+row.wfId+'\',\''+row.pkId+'\')"><i class="fa fa-save"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="twfurgentOpen(\'' + row.pkId + '\')"><i class="fa fa-save"></i>催办</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.pkId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 重新派单
    function resend() {
        var wfId = $('#pkId').val();
        var url = prefix+'/cmnFile/telresendto/'+wfId+'?sbId=0';
        var width = '85%';
        var height = '95%';
        var config = {
            id: 'dlSendToSon',
            title: '拟办部门',
            width: width,
            height: height,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(null,window.name);
            }
        };
        $.modal.openOptions(config);
    }

    //TODO 此方法废弃
    function proposed() {
        var layerIdx = parent.layer.getFrameIndex(window.name);
        var iframeName = 'layui-layer-iframe'+layerIdx;
        let pkId = $('#pkId').val();
        let telId = $('#getDealPK').val();
        var url = send + "/proposed/" + pkId+"?wfId="+pkId+"&telId="+telId;
        var width = '80%';
        var config = {
            id: 'deptdialog',
            title: '拟办部门',
            width: width,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler(iframeName);
            }
        };
        $.modal.openOptions(config);
    }

    function refreshTable() {
        $.table.refresh();
    }

    function EditViewById(wfId,id){
        var url = send + "/editDept/"+wfId+"/"+id+"?wfId="+wfId+"&telId="+id;
        var width = '70%';
        var config = {
            id: 'deptdialog',
            title: '拟办部门',
            width: width,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
            }
        };
        $.modal.openOptions(config);
        // $.modal.open('修改拟办部门', url);
    }

    function twfurgentOpen(value) {
        $.modal.open('催办',twfurgent+"/twfurgentAdd/"+value);
    }

    // 批量撤回信息
    function backAll() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要撤回选中的" + rows.length + "条数据吗?", function() {
            var url = prefix +'/cmnFile/withdraw/'+rows.join();
            // var data = { "pkId": rows.join() };
            $.operate.submit(url, "post", "json");
        });
    }
</script>
</body>
</html>